﻿package mortal.game.view.signUp.lineOn.panel
{
    import com.gengine.core.frame.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.signUp.lineOn.item.*;
    import mortal.game.view.signUp.sevenDayLogin.data.*;
    import mortal.game.view.signUp.view.*;
    import mortal.mvc.core.*;

    public class LineOnGetRewardPanel extends SignUpViewBase
    {
        protected var _rewadBg:GImageBitmap;
        public var _rewardListPanel:LineOnGiftPanel;
        protected var _getBtn:GLoadingButton;
        protected var _bgMM:GImageBitmap;
        protected var _lineSp:ScaleBitmap;
        protected var _hourNum:BitmapNumberText;
        protected var _minNum:BitmapNumberText;
        protected var _secNum:BitmapNumberText;
        protected var _ignorCheckBox:GCheckBox;
        public var uiLoadComplete:Boolean = false;
        private var _timer:SecTimer;
        private var _selectCk:Boolean;
        private var _ckTime:int = 0;

        public function LineOnGetRewardPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.lineOn, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this.uiLoadComplete = true;
            if (this.isDisposed)
            {
                return;
            }
            this._rewadBg = UIFactory.gImageBitmap(ImagesConst.lineOnListBg, 1, 174, this);
            this._rewardListPanel = UIFactory.getUICompoment(LineOnGiftPanel) as LineOnGiftPanel;
            this._rewardListPanel.x = 0;
            this._rewardListPanel.y = 202;
            this.addChild(this._rewardListPanel);
            this._getBtn = UIFactory.gLoadingButton(ImagesConst.LineOnGetBtn_upSkin, 289, 481, 103, 44, this);
            this._bgMM = UIFactory.gImageBitmap(ImagesConst.lineOnMM, 0, 0, this);
            this._lineSp = UIFactory.bg(48, 469, 593, 2, this, ImagesConst.SplitLine);
            this._hourNum = UIFactory.bitmapNumberText(438, 69, "LineOnRewardNum.png", 20, 25, -8, this, 13, 1);
            this._hourNum.text = "0";
            this._minNum = UIFactory.bitmapNumberText(496, 69, "LineOnRewardNum.png", 20, 25, -2, this);
            this._minNum.text = "29";
            this._secNum = UIFactory.bitmapNumberText(576, 69, "LineOnRewardNum.png", 20, 25, -2, this);
            this._secNum.text = "19";
            this._ignorCheckBox = UIFactory.checkBox("" + Language.getString(71931), 33, 500, 100, 28, this);
            this._ignorCheckBox.configEventListener(Event.CHANGE, this.onCk);
            this._ignorCheckBox.selected = this._selectCk;
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onGetHd);
            this._getBtn.enabled = false;
            this.initCells();
            this._timer = new SecTimer();
            this._timer.addListener(TimerType.ENTERFRAME, this.updateTimeShow);
            this._timer.start();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            Cache.instance.lineOn.getGodTips = "";
            if (this.uiLoadComplete == false)
            {
                return;
            }
            SevenDayLoginUtil.removeArrow(this._getBtn);
            Cache.instance.lineOn.getIndex = -1;
            this._rewardListPanel.dispose(param1);
            this._rewadBg.dispose(param1);
            this._getBtn.dispose(param1);
            this._bgMM.dispose(param1);
            this._lineSp.dispose(param1);
            this._hourNum.dispose(param1);
            this._minNum.dispose(param1);
            this._secNum.dispose(param1);
            this._ignorCheckBox.dispose(param1);
            this._rewardListPanel = null;
            this._rewadBg = null;
            this._getBtn = null;
            this._bgMM = null;
            this._lineSp = null;
            this._hourNum = null;
            this._minNum = null;
            this._secNum = null;
            this._ignorCheckBox = null;
            if (this._timer)
            {
                this._timer.stop();
                this._timer.dispose(param1);
                this._timer = null;
            }
            return;
        }// end function

        private function onCk(event:Event) : void
        {
            this._selectCk = this._ignorCheckBox.selected;
            return;
        }// end function

        private function updateTimeShow(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.lineOn.getLineOnTime();
            var _loc_3:* = int(_loc_2 / 3600);
            var _loc_4:* = int(_loc_2 / 60) % 60;
            var _loc_5:* = _loc_2 % 60;
            var _loc_6:* = _loc_3 + "";
            var _loc_7:* = _loc_4 < 10 ? ("0" + _loc_4) : ("" + _loc_4);
            var _loc_8:* = _loc_5 < 10 ? ("0" + _loc_5) : ("" + _loc_5);
            this._hourNum.text = _loc_6;
            this._minNum.text = _loc_7;
            this._secNum.text = _loc_8;
            this.updateBtn();
            this.updateCellTip();
            return;
        }// end function

        public function initCells() : void
        {
            this.updateTimeShow(null);
            this._rewardListPanel.initCells();
            return;
        }// end function

        public function updateOneCell(param1:Object) : void
        {
            this._rewardListPanel.updateOneCell(param1);
            return;
        }// end function

        private function onGetHd(event:MouseEvent) : void
        {
            var _loc_2:* = getTimer();
            if (_loc_2 - this._ckTime < 1000)
            {
                return;
            }
            this._ckTime = _loc_2;
            this.setBtn(false);
            Cache.instance.lineOn.ignorCk = this._ignorCheckBox.selected;
            Dispatcher.dispatchEvent(new DataEvent(EventName.LineOnUpdateGetRewardCk));
            return;
        }// end function

        private function updateBtn() : void
        {
            Cache.instance.lineOn.hasLineOnReward();
            var _loc_1:* = Cache.instance.lineOn.hasGetFlag;
            this.setBtn(_loc_1);
            return;
        }// end function

        private function setBtn(param1:Boolean) : void
        {
            this.showGuideArrow(param1);
            this._getBtn.enabled = param1;
            if (param1 == false)
            {
                this._getBtn.filters = [FilterConst.colorFilter2];
            }
            else
            {
                this._getBtn.filters = null;
            }
            return;
        }// end function

        private function showGuideArrow(param1:Boolean) : void
        {
            if (param1)
            {
                SevenDayLoginUtil.genGiftArrow(this._getBtn, -10, 21, 2, this);
            }
            else
            {
                SevenDayLoginUtil.removeArrow(this._getBtn);
            }
            return;
        }// end function

        private function updateCellTip() : void
        {
            Cache.instance.lineOn.setResTime();
            this._rewardListPanel.updateCellTime();
            return;
        }// end function

        public function scrollRightOne() : void
        {
            if (this._rewardListPanel)
            {
                this._rewardListPanel.scrollRightOneCell();
            }
            return;
        }// end function

    }
}
